<?php

namespace App\Repositories\Eloquent\Admin;

use App\Repositories\Eloquent\BaseModel;
use EasySwoole\ORM\AbstractModel;


class AdminRoleNodeModel extends AbstractModel
{
    use BaseModel;
    protected $tableName = 'k_admin_role_nodes';
    protected $connectionName = 'wr';
    protected $autoTimeStamp = true;
    protected $createTime = 'add_time';
    protected $updateTime = 'update_time';


    //获取系统用户权限列表
    public function getRoleNodes(int $adminId = 0){
        $datas = $this->create()->alias('a')
               ->join('k_admin_role_party as b','a.id_role = b.id_role','LEFT')
               ->where(['b.id_admin'=>$adminId,'status'=>1])
               ->order('a.id','desc')
               ->column('a.id_nodes');
        return $datas;
    }


    //获取该角色下面的权限
    public function getNodeIds(int $roleId = 0){
         return $this->create()->where('id_role',$roleId)->column('id_nodes');
    }

    //删除角色权限
    public function delNodeByRoleId(int $roleId = 0){
        return $this->create()->destroy(['id_role'=>$roleId]);
    }



}